package com.tianjin.weight.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class UploadFilePathConfig  implements WebMvcConfigurer {
    @Value("${file.staticAccessPath}")
    private String staticAccessPath;

//    @Value("${file.uploadFolder}")
//    private String uploadFolder;

    @Value("${file.uploadFolderWin}")
    private String pathWin;

    @Value("${file.uploadFolderLinux}")
    private String pathLinux;

    @Value("${file.uploadFolderMac}")
    private String pathMac;

    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        //判断是什么系统
        String os = System.getProperty("os.name");
        if(os.toLowerCase().startsWith("win")) {
            registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + pathWin);
        }else if(os.toLowerCase().startsWith("mac")){
            registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + pathMac);
        }else {
            registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + pathLinux);
        }
//
//        registry.addResourceHandler(staticAccessPath).addResourceLocations("file:/" + uploadFolder);
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }
}
